<?php
define('IN_ADMIN',  1);
$admin_dir  = basename(dirname(__FILE__));
$admin_file = 'admin.php';
require(dirname(__FILE__) . '/global.php');
$save_frame = $_SESSION[$G_admin_session_key]['save_frame'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
<?php echo $G_cfg['site_info']['cms_name'], '&nbsp;', $G_cfg['site_info']['cms_ver']; ?> 
&nbsp;
Licensed to&nbsp;<?php echo $G_cfg['site_info']['corp_name']; ?>
</title>
<META name="Robots" content="noindex" />
<meta name="Copyright" content="Zwon Tech" />
<link rel="stylesheet" href="<?php echo $url_global['common']; ?>/css/admin/admincp.css" type="text/css" media="all" />
<script src="<?php echo $url_global['common']; ?>/js/common.js" type="text/javascript"></script>
</head>
<body style="margin: 0px" scroll="no">
<div id="append_parent"></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td colspan="2" height="80">
<div class="mainhd">
<div class="logo">Zwon Cute CMS</div>
<div class="uinfo">
<p></p>
<p class="btnlink"></p>
</div>
<div class="navbg"></div>
<div class="nav">
<ul id="topmenu">
<?php
$js_menu = '';
foreach($G_menu as $k => $v) {
    $js_menu .= "'$k',";
    echo "<li><em><a href=\"javascript:;\" id=\"header_{$k}\" hidefocus=\"true\" onclick=\"toggleMenu('{$k}', '{$v['url']}');\">{$v['title']}</a></em></li>";
}
if($js_menu != '') {
    $js_menu = substr($js_menu, 0, strlen($js_menu)-1);
    $js_menu = "new Array($js_menu)";
}
?>
</ul>
<div class="currentloca">
    <div id="admincpnav" class="contnav"></div>
    <div class="otherbtn">
        您好, 
        <?php echo $_SESSION[$G_admin_session_key]['username'] ;?>
        [<a href="<?php echo $url_global['admin_logout']; ?>" target="_top">退出</a>]
        [<a href="<?php echo $G_web_root; ?>" target="_blank">网站首页</a>]
        <span id="add2custom"></span>
        <a href="###" id="cpmap" onClick="showMap();return false;"><img src="<?php echo $url_global['common']; ?>/images/btn_map.gif" title="后台导航" width="72" height="18" /></a>
    </div>
</div>

</div>
</div>
</td>
</tr>
<tr>
<td valign="top" width="160" class="menutd">
<div id="leftmenu" class="menu">
<?php
/**
 * 从$G_menu_sub中取出子菜单
 * 
 *
 */
foreach($G_menu_sub as $k => $v) {
    echo "<ul id=\"menu_{$k}\" style=\"display: none\">";
    foreach($v as $kk => $vv) {
        $op = explode('_', $kk);
        if(sizeof($op) == 3) {
            $suburl = $G_admincp . '?mod=' . $op[0] . '&action=' . $op[1] . '&cata=' . $op[2];
        } elseif(sizeof($op) == 2) {
            $suburl = $G_admincp . '?mod=' . $op[0] . '&action=' . $op[1];
        } else {
            $suburl = $G_admincp . '?mod=' . $kk;
        }
        echo "<li><a href=\"$suburl\" hidefocus=\"true\" target=\"main\">{$vv}</a></li>";
    }
    echo "</ul>";
}
?>
</div>
</td>
<td valign="top" width="100%" class="mask">
<iframe src="about:blank" name="<?php echo $save_frame; ?>" id="<?php echo $save_frame; ?>" scrolling="0" width="0" height="0"></iframe>
<iframe src="admin.php?mod=admin&action=home&sid=<?php echo session_id(); ?>" name="main" width="100%" height="100%" frameborder="0"scrolling="yes" style="overflow: visible;"></iframe></td>
</tr>
</table>

<div class="copyright">
	<p>&copy; <?php echo $G_cfg['site_info']['cms_name']; ?> </p>
</div>

<div id="cpmap_menu" class="custom" style="display:none">
	<div class="cside">
		<ul class="cslist" id="custommenu"></ul>
	</div>
	<div class="cmain" id="cmain"></div>
	<div class="cfixbd"></div>
</div>

<script type="text/JavaScript">
	var headers = <?php echo $js_menu; ?>;
	var admincpfilename = '<?php echo $G_admincp; ?>';
	function toggleMenu(key, url) {
		if(key == 'index' && url == 'home') {
			if(is_ie) {
				doane(event);
			}
			top.location.href = 'main.php' + '?frames=yes';
			return false;
		}
		for(var k in headers) {
			if($('menu_' + headers[k])) {
				$('menu_' + headers[k]).style.display = headers[k] == key ? '' : 'none';
			}
		}
		var lis = $('topmenu').getElementsByTagName('li');
		for(var i = 0; i < lis.length; i++) {
			if(lis[i].className == 'navon') lis[i].className = '';
		}
		$('header_' + key).parentNode.parentNode.className = 'navon';
		if(url) {
			parent.main.location = admincpfilename + '?' + url;
			var hrefs = $('menu_' + key).getElementsByTagName('a');
			for(var j = 0; j < hrefs.length; j++) {
				hrefs[j].className = hrefs[j].href.substr(hrefs[j].href.indexOf(admincpfilename + '?action=') + 19) == url ? 'tabon' : (hrefs[j].className == 'tabon' ? '' : hrefs[j].className);
			}
		}
		return false;
	}
	function initCpMenus(menuContainerid) {
		var key = '';
		var hrefs = $(menuContainerid).getElementsByTagName('a');
		for(var i = 0; i < hrefs.length; i++) {
			if(menuContainerid == 'leftmenu' && !key && 'action=home'.indexOf(hrefs[i].href.substr(hrefs[i].href.indexOf(admincpfilename + '?action=') + 12)) != -1) {
				key = hrefs[i].parentNode.parentNode.id.substr(5);
				hrefs[i].className = 'tabon';
			}
			if(!hrefs[i].getAttribute('ajaxtarget')) hrefs[i].onclick = function() {
				if(menuContainerid != 'custommenu') {
					var lis = $(menuContainerid).getElementsByTagName('li');
					for(var k = 0; k < lis.length; k++) {
						if(lis[k].firstChild.className != 'menulink') lis[k].firstChild.className = '';
					}
					if(this.className == '') this.className = menuContainerid == 'leftmenu' ? 'tabon' : 'bold';
				}
				if(menuContainerid != 'leftmenu') {
					var hk, currentkey;
					var leftmenus = $('leftmenu').getElementsByTagName('a');
					for(var j = 0; j < leftmenus.length; j++) {
						hk = leftmenus[j].parentNode.parentNode.id.substr(5);
						if(this.href.indexOf(leftmenus[j].href) != -1) {
							leftmenus[j].className = 'tabon';
							if(hk != 'index') currentkey = hk;
						} else {
							leftmenus[j].className = '';
						}
					}
					if(currentkey) toggleMenu(currentkey);
					hideMenu();
				}
			}
		}
		return key;
	}
	var header_key = initCpMenus('leftmenu');
	toggleMenu(header_key ? header_key : 'system');
	function initCpMap() {
		var ul, hrefs, s;
		s = '<ul class="cnote"><li><img src="<?php echo $G_web_common; ?>/images/btn_map.gif" /></li><li> 按 “ ESC ” 键展开 / 关闭此菜单</li></ul><table class="cmlist" id="mapmenu"><tr>';

		for(var k in headers) {
			if(headers[k] != 'index' && headers[k] != 'uc') {
				s += '<td valign="top"><ul class="cmblock"><li><h4>' + $('header_' + headers[k]).innerHTML + '</h4></li>';
				ul = $('menu_' + headers[k]);
				hrefs = ul.getElementsByTagName('a');
				for(var i = 0; i < hrefs.length; i++) {
					s += '<li><a href="' + hrefs[i].href + '" target="' + hrefs[i].target + '" k="' + headers[k] + '">' + hrefs[i].innerHTML + '</a></li>';
				}
				s += '</ul></td>';
			}
		}
		s += '</tr></table>';
		return s;
	}
	$('cmain').innerHTML = initCpMap();
	initCpMenus('mapmenu');
	var cmcache = false;
	function showMap() {
		showMenu('cpmap', true, 3, 3);
		if(!cmcache) ajaxget(admincpfilename + '?action=misc&operation=custommenu&' + Math.random(), 'custommenu', '');
	}
	function resetEscAndF5(e) {
		e = e ? e : window.event;
		actualCode = e.keyCode ? e.keyCode : e.charCode;
		if(actualCode == 27) {
			if($('cpmap_menu').style.display == 'none') {
				showMap();
			} else {
				hideMenu();
			}
		}
		if(actualCode == 116 && parent.main) {
			parent.main.location.reload();
			if(document.all) {
				e.keyCode = 0;
				e.returnValue = false;
			} else {
				e.cancelBubble = true;
				e.preventDefault();
			}
		}
	}
	_attachEvent(document.documentElement, 'keydown', resetEscAndF5);


	function uc_left_menu(uc_menu_data) {
		var leftmenu = $('menu_uc');
		leftmenu.innerHTML = '';
		var html_str = '';
		for(var i=0;i<uc_menu_data.length;i+=2) {
			html_str += '<li><a href="'+uc_menu_data[(i+1)]+'" hidefocus="true" onclick="uc_left_switch(this)" target="main">'+uc_menu_data[i]+'</a></li>';
		}
		leftmenu.innerHTML = html_str;
		toggleMenu('uc', '');
		$('admincpnav').innerHTML = 'UCenter';
	}

	var uc_left_last = null;
	function uc_left_switch(obj) {
		if(uc_left_last) {
			uc_left_last.className = '';
		}
		obj.className = 'tabon';
		uc_left_last = obj;
	}

	function uc_modify_sid(sid) {
		$('header_uc').href = 'http://localhost/travel/bbs/uc_server/admin.php?m=frame&a=main&iframe=1&sid=' + sid;
	}
</script>
</body>
</html>